package com.yeraphael.controller;


import com.yeraphael.entity.Emp;
import com.yeraphael.entity.LoginData;
import com.yeraphael.entity.Result;
import com.yeraphael.service.LoginService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
@RequestMapping("/login")
public class LoginController {

    @Autowired
    private LoginService loginService;


    @PostMapping
    public Result login(@RequestBody Emp emp) {
        log.info("emp: {}", emp);
        LoginData loginData = loginService.login(emp);
        if(loginData == null) {
            return Result.error("用户名或密码错误！！！");
        }
        return Result.success(loginData);
    }
}
